package com.fz.us.admin.dict.dao.impl;

import com.fz.us.admin.base.dao.impl.BaseDaoImpl;
import com.fz.us.admin.dict.dao.DictDao;
import com.fz.us.admin.dict.entity.Dict;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import java.util.List;

/**
 * Dao实现类 - 字典
 * ============================================================================
 * 版权所有 2016 。
 *
 * @author fallenpanda
 * @version 1.0 2016-07-21 。
 * ============================================================================
 */
@Repository
public class DictDaoImpl extends BaseDaoImpl<Dict, String> implements DictDao {

    @SuppressWarnings("unchecked")
    public List<Dict> listSystem() {
        String hql = "from "+Dict.class.getName()+" model where model.keyId is null and ( model.state = 'Enable' or model.state = 'Disenable' ) order by model.createTime asc ";
        return getSession().createQuery(hql).list();
    }

    @SuppressWarnings("unchecked")
    public List<Dict> listDefault(String keyId) {
        Assert.notNull(keyId ,"keyId is required");
        String hql = "from "+Dict.class.getName()+" model where ( model.keyId is null and model.ifKey = 0 and model.state = 'Enable' ) or ( model.keyId = :keyId and ( model.state = 'Enable' or model.state = 'Disenable' ) ) order by model.createTime asc ";
        return getSession().createQuery(hql).setParameter("keyId", keyId).list();
    }

}
